/*
 * @lc app=leetcode.cn id=905 lang=cpp
 *
 * [905] 按奇偶排序数组
 */

// @lc code=start
class Solution
{
public:
  vector<int> sortArrayByParity(vector<int>& nums)
  {
    int L = 0, R = nums.size() - 1;
    while (L < R) {
      while (L < R && !(nums[L] & 1))
        ++L;
      while (L < R && nums[R] & 1)
        --R;
      int tmp = nums[L];
      nums[L] = nums[R];
      nums[R] = tmp;
    }
    return nums;
  }
};
// @lc code=end
